Android Push Notifications
Configuring RemoteMessages reception from Firebase
To config Grouplink Regular Notifications in foreground, it is needed to config the notification reception from FCM.
1. Get the Notification from the notification inside the RemoteMessage.
Full FirebaseMessagingService extension implementation result:
import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.grouplink.marketdemo.notification.NotificationManager
import com.grouplink.marketdemo.notification.NotificationManager.Companion.createNotificationChannelVisible
import com.grouplinknetwork.GroupLink
import java.util.*
class FirebaseService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
/*
* To show a notification with the app in foreground, please override
* this method, and build a new Notification from the RemoteMessage
* received.
*/
super.onMessageReceived(message)
}
override fun onNewToken(token: String) {
GroupLink.setFirebaseToken(applicationContext, token)
//Create the notification channel as soon as possible,
//to be able to receive notifications.
createNotificationChannelVisible(this)
super.onNewToken(token)
}
}
Adding meta-data for Custom Notification Channel
To configure a custom Notification Channel for firebase notifications, please add the following lines:
<application>
.
.
.
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_gl_alarm" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/gl_blue" />
</application>